<?php 

use \Workerman\Worker;
use \Workerman\WebServer;
use \GatewayWorker\Gateway;
use \GatewayWorker\BusinessWorker;
use \Workerman\Autoloader;
// 自动加载类
require_once GKROOT . '/vendor/autoload.php';
// 配置文件
$config = require __DIR__ . '/config.php';

// gateway 进程，这里使用Text协议，可以用telnet测试
//采用 tcp协议  或者  Websocket
$gateType = $config['gateway']['gateway_type'];
if(!$gateType){
    $gateType = 'tcp';
}
$gateway = new Gateway($gateType."://0.0.0.0:".$config['gateway']['gateway_port']);
// gateway名称，status方便查看
$gateway->name = $config['gateway']['gateway_name'];
// gateway进程数
$gateway->count = $config['gateway']['gateway_nums'];
// 本机ip，分布式部署时使用内网ipgateway_nums
$gateway->lanIp = $config['gateway']['lanIp'];//内网ip
// 内部通讯起始端口，假如$gateway->count=4，起始端口为4000
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口 
$gateway->startPort = $config['gateway']['startPort'];
// 服务注册地址
$gateway->registerAddress =$config['registerAddress'];

// 心跳间隔
$gateway->pingInterval = $config['gateway']['pingInterval'];
// 心跳间隔
$gateway->pingNotResponseLimit = $config['gateway']['pingNotResponseLimit'];
// 心跳数据
$gateway->pingData = $config['gateway']['pingData'];

 
// 当客户端连接上来时，设置连接的onWebSocketConnect，即在websocket握手时的回调
$gateway->onConnect = function($connection){
    //若使用二进制数据打开下面的注释
    //$connection->websocketType = Workerman\Protocols\Websocket::BINARY_TYPE_ARRAYBUFFER;
}; 


// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

